package leetcode.code1027;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {
	
	public int longestArithSeqLength(int[] nums) {
		int len = nums.length;
		int[][] dp = new int[len][1001];
		int ans = 0;
		for (int i = 0; i < dp.length; i++) {
			int n1 = nums[i];
			for (int j = 0; j < i; j++) {
				int n2 = nums[j];
				int diff = n1 - n2 + 500;
				dp[i][diff] = Math.max(dp[i][diff], dp[j][diff] + 1);
				ans = Math.max(ans, dp[i][diff]);
			}
		}
		return ans + 1;
	}

	@Override
	public void debug4() {
		H.compare(4, this.longestArithSeqLength(H.str2array3("[3,6,9,12]")));
		H.compare(3, this.longestArithSeqLength(H.str2array3("[9,4,7,2,10]")));
		H.compare(4, this.longestArithSeqLength(H.str2array3("[20,1,15,3,10,5,8]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
